package com.demo.controller;

import com.demo.pojo.ResultVO;
import com.demo.pojo.User;
import com.demo.pojo.UserDTO;
import com.demo.service.UserService;
import jakarta.mail.MessagingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
/**
 * 用户控制类
 */
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 注册
     * @return
     */
    @PostMapping("/register")
    public ResultVO register(@RequestBody UserDTO userDTO){
        log.info("用户注册:{}",userDTO);
        return userService.register(userDTO);
    }
    /**
     * 注册发送验证码
     */
    @GetMapping("/getCode")
    public ResultVO getCode(@RequestParam String email) throws MessagingException {
        log.info("发送注册验证码:{}",email);
        return userService.getCode(email);
    }
    /**
     * 登录发送验证码
     */
    @GetMapping("/getCodeLogin")
    public ResultVO getCodeLogin(@RequestParam String email) throws MessagingException {
        log.info("发送登录验证码:{}",email);
        return userService.getCodeLogin(email);
    }
    /**
     *忘记密码发送验证码
     */
    @GetMapping("/getCodeForget")
    public ResultVO getCodeForget(@RequestParam String email) throws MessagingException {
        log.info("忘记密码发送验证码:{}",email);
        return userService.getCodeForget(email);
    }
    /**
     * 登录
     */
    @PostMapping("/login")
    public ResultVO login(@RequestBody UserDTO userDTO){
        log.info("用户登录:{}",userDTO);
        return userService.login(userDTO);
    }
    /**
     * 修改密码
     */
    @PostMapping("/updatePassword")
    public ResultVO updatePassword(@RequestBody UserDTO userDTO){
        log.info("修改密码:{}",userDTO);
        return userService.updatePassword(userDTO);
    }
    /**
     * 获取当前登录用户信息
     */
    @GetMapping("/getCurrentUser")
    public ResultVO<User> getCurrentUser(){
        log.info("获取当前登录用户信息");
        return userService.getCurrentUser();
    }




}
